home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
smaltalk
/
manchest.lha
/
MANCHESTER
/
manchester
/
4.1
/
Browser-spellingCheck.st
< prev
next >
Wrap
Text File
|
1993-07-24
|
6KB
|
148 lines
" NAME Browser-spellingCheck
AUTHOR Bernard Horan <bernard@is.morgan.com>
CONTRIBUTOR Bernard Horan <bernard@is.morgan.com>
FUNCTION adds spelling correction to some browser menus
ST-VERSIONS 4.1
PREREQUISITES
CONFLICTS
DISTRIBUTION world
VERSION 1.0
DATE December 1992
SUMMARY Adds the following three spelling corrections to the
browser: findClass (if no class exists for the entered string then try and find
one that does -- this also checks with the user that the edited text may be
discarded before requesting for the class name); implementors (if no
implementor exists with the name provided, then try and find one that does);
senders (similar to implementors). BH 4/12/92"
'From Objectworks\Smalltalk(R), Release 4.1 of 15 April 1992 on 27 November 1992 at 2:39:55 am'!
!Browser methodsFor: 'private-category functions'!
findClass
"Prompt for a class and position myself there."
"Modified by Bernard Horan, 27 November 1992, to
send #changeRequest BEFORE asking user for class name"
| testClass |
self changeRequest ifFalse: [^self].
testClass := self pickAClass: 'Find class:'.
testClass = '' ifTrue: [^self].
testClass == nil ifTrue: [^DialogView warn: 'No matching class'].
testClass isBehavior ifFalse: [testClass := testClass class].
testClass isMeta ifTrue: [testClass := testClass soleInstance].
self newCategoryList: testClass category.
self newClassList: testClass name!
pickAClass: prompt
"Choose a class with a prompter. Bring up menu for wildcards.
Answer the an empty string if that's what the user returned or
if the user selects outside the menu, answer nil if the user picks
a name that does not match any class name."
| destClassName destClass classes chosenSelector |
destClassName := DialogView request: prompt initialAnswer: ParagraphEditor currentSelection.
destClassName = '' ifTrue: [^''].
(destClassName findString: '*' startingAt: 1) ~=0
ifTrue: [classes := OrderedCollection new.
Cursor execute showWhile:
[classes := Smalltalk classNames select: [ :cn | destClassName match: cn]].
(classes == nil or: [classes size = 0]) ifTrue: [^nil].
(chosenSelector := (PopUpMenu labelList: (Array with: classes)) startUp) = 0
ifTrue: [^'']
ifFalse: [destClassName := classes at: chosenSelector]]
ifFalse: [destClassName :=
Smalltalk keys
detect: [ :cn | destClassName match: cn]
ifNone: [self correctClass: destClassName].
destClassName isNil ifTrue:[^nil]].
destClass := Smalltalk at: destClassName asSymbol ifAbsent: [^nil].
meta ifTrue: [destClass := destClass class].
^destClass! !
!Browser methodsFor: 'private'!
correctClass: aString
"Attempt to find a class with the specified (incorrrect) name.
Bernard Horan, 27 November 1992"
| candidates smaller larger class |
candidates := OrderedCollection new.
smaller := aString size - 4.
larger := aString size + 4.
Smalltalk keysDo: [:k |
(k size between: smaller and: larger)
ifTrue:
[| score |
score := k spellAgainst: aString.
score >= 50 ifTrue: [candidates add: k]]].
candidates isEmpty ifTrue: [^nil].
candidates := candidates asSortedCollection.
class := (PopUpMenu labelArray: candidates values: candidates) startUpWithHeading: 'Correct to...'.
^class == 0 ifFalse:[class]! !
!Browser class methodsFor: 'browsing'!
promptThenBrowseCalls
"Prompt the user for a selector or selector pattern. If a selector,
then browse all calls on that selector. If a pattern, then show a
menu of selectors matching that pattern and browse the selected
one."
"Augmented to attempt to correct typing error.
Bernard Horan, 27 November 1992"
"Browser promptThenBrowseCalls"
| trial symbol coll |
trial := DialogView
request: 'Browse calls on what?'
initialAnswer: ParagraphEditor currentSelection.
trial isEmpty ifTrue: [^self].
((trial includes: $*) or: [trial includes: $#])
ifTrue: "pattern"
[coll := OrderedCollection new.
Cursor wait showWhile:
[Symbol allSubInstancesDo:
[:sym | (trial match: sym ignoreCase: false) ifTrue: [coll add: sym]]].
symbol := self showMenuThenBrowseCalls: coll]
ifFalse: "single item"
[symbol := Symbol findInterned: trial.
"Attempt to correct typing error"
symbol isNil ifTrue:[symbol := Symbol correctMessage: trial].
symbol isNil ifTrue: [DialogView warn: 'Nobody'. ^self].
"it doesn't exist, therefore no senders"
^self browseAllCallsOn: symbol]!
promptThenBrowseImplementors
"Prompt the user for a selector or selector pattern. If a selector,
then browse all implementors of that selector. If a pattern, then show a
menu of selectors matching that pattern and browse the selected
one."
"Augmented to attempt to correct typing error.
Bernard Horan, 27 November 1992"
"Browser promptThenBrowseImplementors"
| trial symbol coll |
trial := DialogView
request: 'Browse implementors of what?'
initialAnswer: ParagraphEditor currentSelection.
trial isEmpty ifTrue: [^self].
((trial includes: $*) or: [trial includes: $#])
ifTrue: "pattern"
[coll := OrderedCollection new.
Cursor wait showWhile:
[self allImplementedMessages do:
[:sym | (trial match: sym ignoreCase: false) ifTrue: [coll add: sym]]].
symbol := self showMenuThenBrowse: coll]
ifFalse: "single item"
[symbol := Symbol findInterned: trial.
"Attempt to correct typing error"
symbol isNil ifTrue:[symbol := Symbol correctMessage: trial].
symbol isNil ifTrue: [DialogView warn: 'Nobody'. ^self].
"it doesn't exist, therefore no implementors"
^self browseAllImplementorsOf: symbol]! !